using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BlueFinity.mvNET.CoreObjects;


namespace mvLibrary
{
    public partial class PrinterForm : Form
    {
        private Dictionary<string,string> printers = new Dictionary<string,string>();
        private string _defaultPrinter = "0";
        private bool _printFromPick;
        private mvAccount _pickAccount;
        public mvAccount PickAccount
        {
            get { return _pickAccount; }
            set { _pickAccount = value; }
        }
        public bool PrintFromPick
        {
            get { return _printFromPick; }
            set { _printFromPick = value; }
        }
        public string DefaultPrinter
        {
            get { return _defaultPrinter; }
            set { _defaultPrinter = value; }
        }
        public PrinterForm()
        {
            InitializeComponent();
        }

        

        private void PrinterForm_Load(object sender, EventArgs e)
        {
         // leer impresoras pick
            mvItem printersList = new mvItem();
            string strPrintersList = "";
            try
            {
                _pickAccount.Login();
                _pickAccount.CallProg("SEL.PRINTERS.NET", ref strPrintersList);
                _pickAccount.Logout();
                printersList.Contents = strPrintersList;
            }
            catch
            {
                _pickAccount.Logout();
                printersList[1] = "0";
                printersList[2] = "Server";
            }
            for (int a = 1; a <= printersList.DCount(1); ++a)
            {
                printers.Add(printersList.get_Text(1,a,1), printersList.get_Text(2,a,1));
            }
            comboPrinters.DataSource = new BindingSource(printers, null);
            comboPrinters.ValueMember = "Key";
            comboPrinters.DisplayMember = "Value";
            comboPrinters.SelectedValue = _defaultPrinter;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboPrinters.SelectedIndex == -1)
            {
                MessageBox.Show("Falta seleccionar impresora !");
                comboPrinters.Focus();
                return;
            }
            _printFromPick = true;
            _defaultPrinter = comboPrinters.SelectedValue.ToString();
          

        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (comboPrinters.SelectedIndex == -1)
            {
                MessageBox.Show("Falta seleccionar impresora !");
                comboPrinters.Focus();
                return;
            }
            _printFromPick = false;
           
        }
    }
}

